package com.neuedu.dao.impl;

import com.neuedu.dao.HouseServiceDao;
import com.neuedu.model.FangChan;
import com.neuedu.model.User;
import com.neuedu.model.XiaoQu;
import com.neuedu.utils.DbUtil;

import java.util.ArrayList;
import java.util.List;

public class HouseServiceDaoImpl implements HouseServiceDao {
    @Override
    public List<FangChan> selectPage(String minDate, String maxDate, String likeName, Integer limitParam1, Integer limitParam2) {
        String where = " 1=1 ";
        List<Object> params = new ArrayList<>();
        if (minDate != null && !minDate.equals("")) {
            where = where + "and ruzhushijian >= ?";
            params.add(minDate);
        }
        if (maxDate != null && !maxDate.equals("")) {
            where = where + "and ruzhushijian <= ?";
            params.add(maxDate);
        }
        if (likeName != null && !likeName.equals("")) {
            where = where + "and fanchanmingcheng like ?";
            params.add("%" + likeName + "%");
        }
        where=where+"order by fangchanid  limit ?,?";
        params.add(limitParam1);
        params.add(limitParam2);
        List<FangChan>result=  DbUtil.select(FangChan.class,where,params.toArray());
        return result;

    }

    @Override
    public int count(String minDate, String maxDate, String likeName) {
        String where=" 1=1 ";
        List<Object> params=new ArrayList<>();
        if(minDate!=null&&!minDate.equals("")){
            where=where+"and chuangjianshijian >= ?";
            params.add(minDate);
        }
        if(maxDate!=null&&!maxDate.equals("")){
            where=where+"and chuangjianshijian <= ?";
            params.add(maxDate);
        }
        if(likeName!=null&&!likeName.equals("")){
            where=where+"and mingcheng like ?";
            params.add("%"+likeName+"%");
        }
        List<FangChan> result = DbUtil.select(FangChan.class, where, params.toArray());
        return result==null?0:result.size();
    }

    @Override
    public int insertFanChan(FangChan fangChan) {

            return DbUtil.insertSelective(fangChan);

    }

    @Override
    public int delFanchan(Integer[] ids) {
        String where="fangchanid in (";
        for (int i=0;i<ids.length;i++){
            where=where+"?";
            if(i!=ids.length-1){
                where=where+",";
            }else{
                where=where+")";
            }
        }

        return DbUtil.delete(FangChan.class,where,ids);
    }


}
